dictA = {'name':'Alex'}
dict2 = dictA

# clear方法: 用于清除所有的元素
dictA.clear()
print(dictA)
# {}
print(dict2)
# {}

# ----------------------------

# copy方法 / deepcopy函数
# copy方法：浅拷贝，用于复制一个字典, 该方法返回复制后的新字典.
# 注意: python中的浅拷贝为第一层数据不互相影响, 第二层开始互相影响
dictB = {'name':'Alex', 'age':18, 'house': {'house1': 'Beijing', 'house2':'Haikou'}}
newDict = dictB.copy()
print('newDict === ', newDict)
# newDict ===  {'name': 'Alex', 'age': 18, 'house': {'house1': 'Beijing', 'house2': 'Haikou'}}

newDict['name'] = 'Rose'
newDict['house']['house1'] = 'Shanghai'
print(newDict)
print(dictB)
# {'name': 'Rose', 'age': 18, 'house': {'house1': 'Shanghai', 'house2': 'Haikou'}}
# {'name': 'Alex', 'age': 18, 'house': {'house1': 'Shanghai', 'house2': 'Haikou'}}

# ----------------------------

dictC = {'name':'Alex', 'age':18, 'house': {'house1': 'Beijing', 'house2':'Haikou'}}
newDictC = dictC.copy()
dictC['name'] = 'William'
dictC['house']['house2'] = 'Sanya'
print(newDictC)
print(dictC)
# {'name': 'Alex', 'age': 18, 'house': {'house1': 'Beijing', 'house2': 'Sanya'}}
# {'name': 'William', 'age': 18, 'house': {'house1': 'Beijing', 'house2': 'Sanya'}}

# ----------------------------
# ----------------------------

from copy import deepcopy

dictD = {'name':'Alex', 'age':18, 'house': {'house1': 'Beijing', 'house2':'Haikou'}}

newDictD = deepcopy(dictD)
print('dictD === ', dictD)

dictD['name'] = 'Wang'
newDictD['house']['house2'] = 'Shenzhen'
print(dictD)
print(newDictD)
# {'name': 'Wang', 'age': 18, 'house': {'house1': 'Beijing', 'house2': 'Haikou'}}
# {'name': 'Alex', 'age': 18, 'house': {'house1': 'Beijing', 'house2': 'Shenzhen'}}